package net.zjitc.yaobei_backed.service.sms;

import net.zjitc.yaobei_backed.config.SmsConfig;
import net.zjitc.yaobei_backed.service.sms.impl.ConsoleSmsProvider;
import net.zjitc.yaobei_backed.service.sms.impl.JuheSmsProvider;
// 暂时注释掉，等腾讯云SDK依赖下载成功后再取消注释
// import net.zjitc.yaobei_backed.service.sms.impl.TencentSmsProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 短信服务商工厂类
 */
@Component
public class SmsProviderFactory {
    
    @Autowired
    private SmsConfig smsConfig;
    
    @Autowired
    private JuheSmsProvider juheSmsProvider;
    
    // 暂时注释掉，等腾讯云SDK依赖下载成功后再取消注释
    // @Autowired(required = false)
    // private TencentSmsProvider tencentSmsProvider;
    
    private final ConsoleSmsProvider consoleSmsProvider = new ConsoleSmsProvider();
    
    /**
     * 根据配置获取短信服务商
     * @return 短信服务商实例
     */
    public SmsProvider getProvider() {
        // 如果未启用，使用控制台模式
        if (!smsConfig.getEnabled()) {
            return consoleSmsProvider;
        }
        
        String provider = smsConfig.getProvider();
        if (provider == null || provider.isEmpty()) {
            return consoleSmsProvider;
        }
        
        switch (provider.toLowerCase()) {
            case "juhe":
                return juheSmsProvider;
            case "tencent":
                // 暂时返回控制台模式，等腾讯云SDK依赖下载成功后再取消注释
                // return tencentSmsProvider;
                System.out.println("警告：腾讯云短信功能暂时禁用，使用控制台模式。等SDK依赖下载成功后再启用。");
                return consoleSmsProvider;
            case "console":
            default:
                return consoleSmsProvider;
        }
    }
}

